package com.goods.business.utils;

import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

/**
 * @author Decheng Kong
 * @date 2021/11/10 02:47
 */
public class HttpUtils {

    public static Long getUserIdByUserName(String token, String username) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
        headers.add("Authorization", token);
        HttpEntity<String> entity = new HttpEntity<>("body", headers);
        String url
                = "http://localhost:8989/system/user/getUserId?userName=";
        ResponseEntity<Long> exchange = restTemplate.exchange(url + username, HttpMethod.GET, entity, Long.class);

        return exchange.getBody();
    }
}
